#include <QCoreApplication>
#include <QDebug>
#include "IvwQtInterface.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    IvwQtInterface ivwInterface;

    // Connect signals to slots for demonstration
    QObject::connect(&ivwInterface, &IvwQtInterface::keywordDetected, [](const QString& keyword) {
        qDebug() << "Qt Demo: Keyword Detected:" << keyword;
    });

    QObject::connect(&ivwInterface, &IvwQtInterface::errorOccurred, [](const QString& errorMsg) {
        qCritical() << "Qt Demo Error:" << errorMsg;
    });

    // Replace with your actual AIKIT credentials and resource path
    QString appID = "bcf15145"; // Example App ID
    QString apiKey = "3a0e16e1a988d976d094b3835dd899e3"; // Example API Key
    QString apiSecret = "NGMzYmI5MTE0MGYzYjk1ODRlMWRhNDA1"; // Example API Secret
    QString resourcePath = "/demo/resource/many-keywords.txt"; // Example resource path
    int keywordCount = 1;

    if (ivwInterface.init(appID, apiKey, apiSecret, resourcePath, keywordCount)) {
        qDebug() << "IVW Qt Interface initialized. Starting listening...";
        if (!ivwInterface.startListening()) {
            qCritical() << "Failed to start IVW listening.";
        }
    } else {
        qCritical() << "Failed to initialize IVW Qt Interface.";
    }

    // In a real application, you would have a way to stop listening, e.g., a button click
    // For this demo, we'll just run for a short period or until a signal is received.
    // For a QCoreApplication, it will run until quit() is called or all event sources are removed.
    // You might want to add a QTimer to stop it after some time for a non-interactive demo.

    // Example: Stop after 10 seconds for demonstration purposes
    QTimer::singleShot(10000, &ivwInterface, &IvwQtInterface::stopListening);
    QTimer::singleShot(11000, &ivwInterface, &IvwQtInterface::cleanup);
    QTimer::singleShot(12000, &a, &QCoreApplication::quit);

    return a.exec();
}
